
@extends('common.header')

<!-- 1.添加meta csrf_token -->
<meta name="csrf-token" content="{{ csrf_token() }}"> 
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>
<script type="text/javascript" >
	
	
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	var _token = $('meta[name="csrf-token"]').attr('content');
	
	
	// 批量删除
	function all_del()
	{
		var all	 =	[];
		var key	 =	0;
		$("input[type=checkbox]:checked").each(function(){
			// 遍历 获取每个选中框的值 资讯ID
			var id = $(this).val();
			if( id != 'all' )
			{
				++key;
				all[key] = id ;
			}
		});
		if( key==0 ){
			alert('没有要删除的资讯');
			location.reload();
			return false;
		}
		if( confirm('确定要删除这些资讯吗？') )
		{
			$.ajax({
				type:"post",
				url:"{{ url('/news/delAll') }}",
				data:{all:all,_token:_token},
				async:true,    					
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					location.reload();
				}
			});
		}else
		{
			location.reload();
			return false;
		}
	}
	
	// 批量 取消推荐
	function all_pass()
	{
		var all	 =	[];
		var key	 =	0;
		$("input[type=checkbox]:checked").each(function(){
			// 遍历 获取每个选中框的值 资讯ID
			var id = $(this).val();
			if( id != 'all' )
			{
				++key;
				all[key] = id ;
			}
		});
		if( key==0 ){
			alert('没有要操作的资讯');
			location.reload();
			return false;
		}
		if( confirm('确定要操作这些资讯吗？') )
		{
			$.ajax({
				type:"post",
				url:"{{ url('/newsPassAll') }}",
				data:{all:all,_token:_token},
				async:false,    					
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					if( back['show_info']=='操作成功' )
					{
						setTimeout(function(){
							location.reload(); 
						}, 1000);  
					}
					
				}
			});
		}else
		{
			location.reload();
			return false;
		}
	}
</script>



<br/><br/><br/><br/><br/>

	
<div class="col-xs-12 col-sm-6 col-md-1" >

</div>

<div class="col-xs-12 col-sm-6 col-md-2" >
	<!-- 页面标记 -->
	<mark style="font-size:18px;">资讯列表</mark>
</div>

<div class="col-xs-6 col-md-4">
	<!-- 搜索框 -->
	<form action="{{ url('/news/index') }}/{{ $category_id }}" method='post' >
		<div class="col-lg-6" style="float:left;" >
			<div class="input-group"  >
				
				{{ csrf_field() }}
				
				<input  type="text" name='keyword' class="form-control" placeholder="输入标题进行查询 ...." value="{{ $request or '' }}" style="width:300px;" />
				
				<span class="input-group-btn" style="display:block" >
					<input class="btn btn-success" type="submit" value="Go!" />
					<a class="btn btn-default" href="{{ url('/news/index') }}" />清空条件</a>
				</span>
				
			</div>
		</div>
	</form>
</div>
<div class="col-xs-12 col-sm-6 col-md-2" >
	<div class="dropdown">
		
		<button class="btn btn-success dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
			@if( $category_id==2 )
				英超
			@elseif( $category_id==3 )
				西甲
			@elseif( $category_id==4 )
				意甲
			@elseif( $category_id==5 )
				德甲
			@elseif( $category_id==6 )
				中超
			@else
				全部
			@endif
			<span class="caret"></span>
		</button>
		
		<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
			@if( $category_id=='0' )
				<li><a href="{{ url('/news/index/') }}/2">英超</a></li>
				<li><a href="{{ url('/news/index/') }}/3">西甲</a></li>
				<li><a href="{{ url('/news/index/') }}/4">意甲</a></li>
				<li><a href="{{ url('/news/index/') }}/5">德甲</a></li>
				<li><a href="{{ url('/news/index/') }}/6">中超</a></li>
			@elseif( $category_id=='2' )
				<li><a href="{{ url('/news/index/') }}">全部</a></li>
				<li><a href="{{ url('/news/index/') }}/3">西甲</a></li>
				<li><a href="{{ url('/news/index/') }}/4">意甲</a></li>
				<li><a href="{{ url('/news/index/') }}/5">德甲</a></li>
				<li><a href="{{ url('/news/index/') }}/6">中超</a></li>
			@elseif( $category_id=='3' )
				<li><a href="{{ url('/news/index/') }}">全部</a></li>
				<li><a href="{{ url('/news/index/') }}/2">英超</a></li>
				<li><a href="{{ url('/news/index/') }}/4">意甲</a></li>
				<li><a href="{{ url('/news/index/') }}/5">德甲</a></li>
				<li><a href="{{ url('/news/index/') }}/6">中超</a></li>
			@elseif( $category_id=='4' )
				<li><a href="{{ url('/news/index/') }}">全部</a></li>
				<li><a href="{{ url('/news/index/') }}/2">英超</a></li>
				<li><a href="{{ url('/news/index/') }}/3">西甲</a></li>
				<li><a href="{{ url('/news/index/') }}/5">德甲</a></li>
				<li><a href="{{ url('/news/index/') }}/6">中超</a></li>
			@elseif( $category_id=='5' )
				<li><a href="{{ url('/news/index/') }}">全部</a></li>
				<li><a href="{{ url('/news/index/') }}/2">英超</a></li>
				<li><a href="{{ url('/news/index/') }}/3">西甲</a></li>
				<li><a href="{{ url('/news/index/') }}/4">意甲</a></li>
				<li><a href="{{ url('/news/index/') }}/6">中超</a></li>
			@elseif( $category_id=='6' )
				<li><a href="{{ url('/news/index/') }}">全部</a></li>
				<li><a href="{{ url('/news/index/') }}/2">英超</a></li>
				<li><a href="{{ url('/news/index/') }}/3">西甲</a></li>
				<li><a href="{{ url('/news/index/') }}/4">意甲</a></li>
				<li><a href="{{ url('/news/index/') }}/5">德甲</a></li>
			@else
			@endif
			
		</ul>
		
	</div>
</div>






<br/><br/><br/>

<!-- 资讯表格 -->
<div class="bs-example" data-example-id="hoverable-table" style="width:90%;margin:0 auto;">
    <table class="table table-hover">
		<thead>
			<tr>
				<th></th>
				<th>id</th>
				<th>标题</th>
				<th>栏目</th>
				<th>状态</th>
				<th>操作</th>
				<th><a href="{{ url('/news/create/') }}" style="font-size:26px;color:#EE3B3B;">添加</a></th>
				<th>作者</th>
				<th>创建时间</th>
			</tr>
		</thead>
		<tbody>
			@forelse($news as $news_info)
				<tr>
					<th>
						<input type="checkbox" name="news_id[]" value="{{ $news_info->id }}" />
					</th>
					<th>{{ $news_info->id }}</th>
					<th style="width:450px;" >{{ $news_info->title }}</th>
					<td style="width:50px;" >{{ $news_info->name }}</td>
					<td style="width:65px;" >{{ $news_info->statusInfo }}</td>
					<td> 
					<!-- 正常 -->
						<a style="color:#008B00;font-size:16px;" href="{{ asset('/news/create/') }}/{{ $news_info->id }}" >编辑</a>
						&nbsp; | &nbsp; 
					@if ( $news_info->status == '3' )
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},4)" >推荐</a>
						&nbsp; | &nbsp; 
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},5)" >头条</a>
					@elseif( $news_info->status == '4' )
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},3)" >审核通过</a>
						&nbsp; | &nbsp; 
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},5)" >头条</a>
					@else( $news_info->status == '5' )
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},3)" >审核通过</a>
						&nbsp; | &nbsp; 
						<a style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="upStatus({{ $news_info->id }},4)" >推荐</a>
					@endif
					</td>
					<td><a style="color:#008B00;font-size:16px;" href="{{ url('/news/addalt/') }}/{{ $news_info->id }}" >封面及图片alt设置</a></td>
					<th scope="row">{{ $news_info->author }}</th>
					<td>{{ $news_info->create_at }}</td>
				</tr>
			@empty
				<tr>
					<td scope="row"><h2>暂无数据</h2></td>
				</tr>
			@endforelse
			<tr>
				<td style="width:60px;">
					<label for="allChoose" >
						<input type="checkbox" name="news_id[]" value='all' ischeck='no' id="allChoose" />全选
					</label>
				</td>
				<td style="width:60px;">
					<a onclick="all_del()" style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" >删除</a>
				</td>
				<td style="width:90px;">
					<a onclick="all_pass();" style="cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-sm" >取消推荐</a>
				</td>
			</tr>
		</tbody>
    </table>
</div>

<!-- 分页 -->
<div style='text-align:center;'>
	{{ $news->appends(['keyword'=>$request])->links() }}
</div>

<div class="badge" style="width:100%;text-align:center;font-size:18px;margin-bottom:70px;" >
		共{{ $news->total() }}条数据
</div>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
	<div class="modal-dialog modal-sm" role="document" id='show_info'  style="margin-top:80px;margin-left:35%;color:white;font-size:19px;">
	</div>
</div>



<script type="text/javascript" >
	
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	var _token = $('meta[name="csrf-token"]').attr('content');
	
	// 执行 修改 资讯状态 
	function upStatus( id,status )
	{
		if( confirm('你真的确定？') )
		{
			$.ajax({
				type:"post",
				url:"{{ url('/news/upstatus/') }}"+'/'+id,
				data:{status:status,_token:_token},
				async:true,    					
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					setTimeout(function(){
						location.reload(); 
					}, 1000);  
					
				}
			});
		}else
		{
			location.reload();
		}
	}
	
	$(function(){
		
		// 批量选中
		$('#allChoose').click(function(){
			// 是否选中
			var res=$(this).attr('ischeck');
			// 未选中
			if( res=='no' ){
				// 设置为 已选中
				$(this).attr('ischeck','yes');
				// 全部选中
				$("input:checkbox").prop('checked',true);
			}else{
				// 设置为 未选
				$(this).attr('ischeck','no');
				// 全部 取消 选中
				$("input:checkbox").prop('checked',false);
			}
		});
	});
	
	
	
</script>


@extends('common.footer')